package cn.itcast.cxf.rs.server;

import cn.itcast.cxf.service.IUserService;
import cn.itcast.cxf.service.UserServiceImpl;
import org.apache.cxf.interceptor.LoggingInInterceptor;
import org.apache.cxf.interceptor.LoggingOutInterceptor;
import org.apache.cxf.jaxws.JaxWsServerFactoryBean;

import javax.xml.ws.Endpoint;

/**
 * Created by Think on 2017/9/18.
 */
public class WS_Server {
    //JDK发布方式
  /*  public static void main(String[] args) {
        IUserService userService = new UserServiceImpl();
        String address = "http://localhost:9999/userService";
        Endpoint.publish(address,userService);
        System.out.println("服务发布成功");
    }*/

    //CXF发布方式
    public static void main(String[] args) {
        IUserService userService = new UserServiceImpl();
        String address = "http://localhost:9999/userService";
        JaxWsServerFactoryBean jaxWsServerFactoryBean = new JaxWsServerFactoryBean();
        jaxWsServerFactoryBean.setServiceBean(userService);
        jaxWsServerFactoryBean.setAddress(address);
        // 想看Soap协议（== http协议+xml数据）
        jaxWsServerFactoryBean.getInInterceptors().add(new LoggingInInterceptor());//输入拦截器日志
        jaxWsServerFactoryBean.getOutInterceptors().add(new LoggingOutInterceptor());//输出拦截器日志
        jaxWsServerFactoryBean.create();
        System.out.println("CXF方式发布服务成功");
    }
}
